from django.db import models
from django.contrib.auth.models import User

class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE,related_name='profile')
    # 真实姓名，团队名，电话号，学号，邮箱，学院，班级
    name = models.CharField(max_length=10,blank=True)
    teamname=models.CharField(max_length=20)
    telephone=models.CharField(max_length=11)
    schoolID = models.CharField(max_length=10, blank=True,unique=True)
    email = models.EmailField()
    college=models.CharField(max_length=10)
    stuclass=models.CharField(max_length=20)
    def __str__(self):
        return f'{self.user.username}-{self.name}-{self.teamname}-{self.telephone}-{self.schoolID}-{self.email}-{self.college}-{self.stuclass}'

class Member(models.Model):
    name=models.CharField(max_length=10,unique=True)
    college=models.CharField(max_length=10)
    stuclass=models.CharField(max_length=20)
    schoolID=models.CharField(max_length=10,unique=True)
    caption=models.ForeignKey(User,on_delete=models.CASCADE,related_name='teamer')
    def __str__(self):
        return f"{self.name}-{self.college}-{self.stuclass}-{self.schoolID}"

class MyGame(models.Model):
    date=models.DateTimeField()
    location=models.CharField(max_length=100)
    state=models.CharField(max_length=10)
    def __str__(self):
        return f"{self.date}-{self.location}-{self.state}"

class TeamMatch(models.Model):
    team = models.ForeignKey(User, on_delete=models.CASCADE)
    match = models.ForeignKey(MyGame, on_delete=models.CASCADE)
    score = models.IntegerField(null=True, blank=True)  # 队伍在比赛中的得分，可以为空
    # 其他与队伍和比赛相关的字段...
    class Meta:
        unique_together = (('team', 'match'),)  # 确保一个队伍在一场比赛中只有一条记录

    def __str__(self):
        return f"{self.team} in {self.match}"

Time_CHOICES = (
    ('2024-11-10 11:00', '2024-11-10 11:00'),
    ('2024-11-10 14:00', '2024-11-10 14:00'),
    ('2024-11-10 15:00', '2024-11-10 15:00'),
    ('2024-11-10 16:00', '2024-11-10 16:00'),
)

class gametest(models.Model):
    user=models.OneToOneField(User, on_delete=models.CASCADE,related_name='gameyy')
    time=models.CharField(max_length=20,choices=Time_CHOICES)
    def __str__(self):
        return f"{self.user}-{self.time}"